package com.tan.steamship.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @description:
 * @author: longshifu
 * @time: 2022/7/31 10:32
 */
@Component
public class SendEmailUtil {
    @Autowired
    JavaMailSenderImpl javaMailSender;

    public  void sendMail(String subject,String text,String[] setTo) {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            helper.setSubject(subject);
            helper.setText(text);
            helper.setFrom("1198247262@qq.com");
            helper.setTo(setTo);
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}
